<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>通知信息管理</title>
	<meta name="decorator" content="default"/>
	<script src="<%=request.getContextPath()%>/static/layer/layer.js"></script>
	
	<script type="text/javascript">
		$(document).ready(function() {
			
			
			function checkDate( sDate, Edate){
				var starttime = $('#starttime').val();  
				var endtime = $('#endtime').val();  
				var start = new Date(starttime.replace("-", "/").replace("-", "/"));  
				var end = new Date(endtime.replace("-", "/").replace("-", "/"));  				
				if(end<start){    
				    return false;    
				} else{
					return true;    
				}
			}
			
			
			
			if((Number($("#ydnum").val())-Number($("#sdnum").val())) <0){
				$("#qxnum").val("0");
			}else{
				$("#qxnum").val($("#ydnum").val()-$("#sdnum").val());
			}	
			
			//$("#qxnum").val($("#ydnum").val()-$("#sdnum").val());
			$("#qdqk").on('click', function() {				
				
				$("#inputForm").attr("action","${ctx}/life/organizeLifeQd/personQd");
				$("#inputForm").submit();

			});
			
			
			$("#btnTj").on('click', function() {
				var sdate=($("#starttime").val()+":00").valueOf(); 	    	//开始时间	
	    		var eDate =($("#endtime").val()+":00").valueOf();           //结束时间
	    	if($("#lifename").val()==null || $("#lifename").val()==""){
				alert("活动名称不能为空！");
			}else if($("#adress").val()==null || $("#adress").val()==""){
				alert("活动地点不能为空！");
			}else if($("#starttime").val()==null || $("#starttime").val()==""){
				alert("提交前请先选择会议开始时间！");
			}else if($("#endtime").val()==null || $("#endtime").val()==""){
				alert("提交前请先选择会议结束时间！");
			}else if(!checkDate($("#starttime").val(),$("#endtime").val())){
				alert("结束时间不能大于开始时间！")
				return false;
			}else if(CKEDITOR.instances.contentzy.getData()==null || CKEDITOR.instances.contentzy.getData()==""){
				alert("提交前请先填写内容摘要！");
			}else if($("#yyzl").val()==null || $("#yyzl").val()==""){
				alert("提交前请先添加资料照片！");
			}else{
		    	var organizeLife=createQd($("#id").val(),$("#yyzl").val(),$("#qjperson").val(),sdate,eDate,$("#fujian").val()
		    			,$("#lifename").val(),
		    			$("#compere").val(),
		    			$("#adress").val(),
		    			$("#column23").val(),
		    			CKEDITOR.instances.contentzy.getData(),
		    			CKEDITOR.instances.zycontent.getData());
				$.ajax({
					type : 'POST',
					url : "${ctx}/life/organizeLifeQd/organizeLifeTj",
					dataType : "json",
					//async : false,//同步  
					contentType : 'application/json',
					data : JSON.stringify(organizeLife),
					success : function(result) {		
						if(result.type == "success"){
							
							top.$.jBox.confirm("组织生活提交成功！","系统提示",function(v,h,f){
								if(v=="ok"){
								   // window.location.reload();//刷新当前页面.
									window.location.href = "${ctx}/life/organizeLifeQd";

								}
							},{buttonsFocus:1});
							top.$('.jbox-body .jbox-icon').css('top','55px');
						} else if(result.type == "error1"){
							alert("组织活动还没有签到，请先添加签到人员！");
						} else {
							$.jBox.info("组织生活提交失败！");
						}
					}
				});
			}				
		});
			
			$("#btnSave").on('click', function() {
				
				var sdate=($("#starttime").val()+":00").valueOf(); 	    	//开始时间	
	    		var eDate =($("#endtime").val()+":00").valueOf();           //结束时间
	    		if($("#lifename").val()==null || $("#lifename").val()==""){
					alert("活动名称不能为空！");
				}else if($("#adress").val()==null || $("#adress").val()==""){
					alert("活动地址不能为空！");
				}else if($("#starttime").val()==null || $("#starttime").val()==""){
					alert("提交前请先选择会议开始时间！");
				}else if($("#endtime").val()==null || $("#endtime").val()==""){
					alert("提交前请先选择会议结束时间！");
				}else if(!checkDate($("#starttime").val(),$("#endtime").val())){
					alert("结束时间不能大于开始时间！")
					return false;
				}else if(CKEDITOR.instances.contentzy.getData()==null || CKEDITOR.instances.contentzy.getData()==""){
					alert("提交前请先填写内容摘要！");
				}else if($("#yyzl").val()==null || $("#yyzl").val()==""){
					alert("提交前请先添加资料照片！");
				}else{
		    	var organizeLife=createQd($("#id").val(),$("#yyzl").val(),$("#qjperson").val(),sdate,eDate,$("#fujian").val(),
		    			$("#lifename").val(),
		    			$("#compere").val(),
		    			$("#adress").val(),
		    			$("#column23").val(),
		    			CKEDITOR.instances.contentzy.getData(),
		    			CKEDITOR.instances.zycontent.getData());
				$.ajax({
					type : 'POST',
					url : "${ctx}/life/organizeLifeQd/organizeLifeSave",
					dataType : "json",
					//async : false,//同步  
					contentType : 'application/json',
					data : JSON.stringify(organizeLife),
					success : function(result) {		
						if(result.type == "success"){
							
							top.$.jBox.confirm("组织生活保存成功！","系统提示",function(v,h,f){
								if(v=="ok"){
								    window.location.reload();//刷新当前页面.

								}
							},{buttonsFocus:1});
							top.$('.jbox-body .jbox-icon').css('top','55px');
						} else {
							$.jBox.info("组织生活保存失败！");
						}
					}
				});		
				}
		});
	});
		//弹出选择请假党员页面
		function selectPersonQj() {
			var html ="";
			$.ajax({
				url : "${ctx}/life/organizeLifeJh/getPersonByOrgid",
				type : "get",
				dataType : "json",
				async : false,//同步  
				success : function(text) {
					html += "<div style='text-align:center'>"
					+"<input id='xgBtn1' onclick='qxQj()' class='btn libts'  type='button' value='全选'/>&nbsp;"
					+"<input id='xgBtn1' onclick='qbxQj()' class='btn libts'  type='button' value='取消全选'/>&nbsp;"
					+"<input id='xgBtn1' onclick='xgQj()' class='btn libts' style='background: red; color: #FFF;' type='button' value='确认'/></div>" 
						+"<div style='padding: 20px 80px;'><table>"
					for (var i = 0; i < text.length; i++) {
						html+="<tr id='"+ (i + 1)+ "'>"
										+ "<td><input type='checkbox' id='idsQj' name='idsQj' value="+text[i].userName+"></td>"
										+ "<td><span style='color:black'>"+text[i].userName+"</span></td>"
										+ "</tr>";
										}
					html+="</table></div>"
				}
			});

			layer.open({
						type : 1,
						skin : 'layui-layer-rim', // 加上边框
						area : [ '300px', '400px' ],
						title : '请选择参会人员',
						content : html
					});
		}
		function xgQj() {
			var idsQj = [];
			$("input[name='idsQj']:checked").each(function() {
				idsQj.push($(this).val());
			});
			if(idsQj.length==0){
				alert("请选择请假人员!");
			}else{
				layer.closeAll();
				$("#qjperson").val(idsQj);
				$("#qxnum").val(idsQj.length);
			}
		}
		
		function qxQj() {
			$("input[name='idsQj']").prop("checked", true);
		}
        function qbxQj() {
        	$("input[name='idsQj']").prop("checked", false);
		}
		
		
		 //创建签到总的对象
		function createQd(id,yyzl,qjperson,starttime,endtime,fujian,lifename,compere,adress,column23,contentzy,zycontent) {
			var object = new Object();
			object.id = id;
			object.yyzl = yyzl;      //资料照片
			object.qjperson = qjperson;   //请假人员
			object.starttime = starttime;//开始时间
			object.endtime = endtime;//结束时间
			object.fujian = fujian;//结束时间
			object.lifename = lifename;
			object.compere = compere;
			object.adress = adress;
			object.column23 = column23;
			object.contentzy = contentzy;
			object.zycontent = zycontent;
			return object;
	    }
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a>组织生活签到明细</a></li>
	</ul>
<form:form id="inputForm" modelAttribute="organizeLife" action="${ctx}/life/organizeLife/save" method="post" class="form-horizontal">
<div class="e-box-title" style="text-align: right">	
				<button class="btn" id="qdqk" data-toggle="modal" data-target="#modal-del">签订情况</button>	
				<button class="btn" id="btnSave" data-toggle="modal" data-target="#modal-del">保存</button>	
				<button class="btn" id="btnTj" data-toggle="modal" data-target="#modal-del">提交</button>	
	</div>
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
        <div class="control-group">
			<label class="control-label">活动名称：</label>
			<div class="controls">
				<form:input path="lifename" htmlEscape="false" style="width:500px" class="input-xlarge required"/>
				<span style='color: red;font-size:50%;' >★</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">类型：</label>
			<div class="controls">
				<c:forEach items="${listStr}" var="order">
						<input type="checkbox" checked="checked" disabled="disabled" >${order.typename }
				</c:forEach>
			</div>
		</div>	
        <div class="control-group">
			<label class="control-label">主持人：</label>
			<div class="controls" style="float:left;margin-left: 20px;">
				<form:input path="compere" htmlEscape="false" style="width:200px" class="input-xlarge required"/>
			</div>
			<label class="control-label" >记录人：</label>
			<div class="" style="float:left;margin-left: 20px;">
				<form:input path="column23" htmlEscape="false" style="width:200px" class="input-xlarge required"/>
			</div>
		</div>
		 <div class="control-group">
			<label class="control-label">活动地点：</label>
			<div class="controls">
				<form:input path="adress" htmlEscape="false" style="width:500px" class="input-xlarge required"/>
				<span style='color: red;font-size:50%;' >★</span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">应到人数：</label>
			<div class="controls" style="float:left;margin-left: 20px;">
				<form:input path="ydnum" htmlEscape="false" style="width:50px" readonly="true" class="input-xlarge required"/>
			</div>
			<label class="control-label" >实到人数：</label>
			<div class="" style="float:left;margin-left: 0px;">
				<form:input path="sdnum" htmlEscape="false" style="width:50px" readonly="true" class="input-xlarge required"/>
			</div>
			<label class="control-label" >缺席人数：</label>
			<div class="" style="float:left;margin-left: 0px;">
				<form:input path="qxnum" htmlEscape="false" style="width:50px" readonly="true" class="input-xlarge required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">计划时间：</label>
			<div class="controls" style="float:left;margin-left: 20px;">
				<input name="jhtime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate " 
				value="<fmt:formatDate value="${organizeLife.jhtime}" pattern="yyyy-MM-dd HH:mm"/>"/>
				<span style='color: red;font-size:50%;' >★</span>
			</div>
			<label class="control-label" >开始时间：</label>
			<div class="" style="float:left;margin-left: 0px;">				
				<input id="starttime" name="starttime" type="text"  maxlength="20" class="input-medium Wdate required"
					value="<fmt:formatDate value="${organizeLife.starttime}" pattern="yyyy-MM-dd HH:mm"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
					<span style='color: red;font-size:50%;' >★</span>
			</div>
			<label class="control-label" >结束时间：</label>
			<div class="" style="float:left;margin-left: 0px;">
				  <input id="endtime" name="endtime" type="text"  maxlength="20" class="input-medium Wdate required"
					value="<fmt:formatDate value="${organizeLife.endtime}" pattern="yyyy-MM-dd HH:mm"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
					<span style='color: red;font-size:50%;' >★</span>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">内容摘要：<span style='color: red;font-size:50%;' >★</span></label>
			<div class="controls">
				<form:textarea id="contentzy" htmlEscape="true" path="contentzy" rows="4" maxlength="200" class="input-xxlarge "/>
				<sys:ckeditor replace="contentzy" uploadPath="/life/organizeLife" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">主要内容：</label>
			<div class="controls">
				<form:textarea id="zycontent" htmlEscape="true" path="zycontent" rows="4" maxlength="200" class="input-xxlarge"/>
				<sys:ckeditor replace="zycontent" uploadPath="/life/organizeLife" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">资料照片：<span style='color: red;font-size:50%;' >★</span></label>
			<div class="controls">				
				<form:hidden id="yyzl" path="yyzl" htmlEscape="false" maxlength="255" class="input-xlarge"/>			
				<sys:ckfinder input="yyzl" type="images" uploadPath="/photo" selectMultiple="true" maxWidth="100" maxHeight="100"/>		
			</div>			
		</div>
		<div class="control-group">
			<label class="control-label">附件：</label>
			<div class="controls">
				<form:hidden id="fujian" path="fujian" htmlEscape="false" maxlength="255" class="input-xlarge"/>
				<sys:ckfinder input="fujian" type="files" uploadPath="/life/organizeLife" selectMultiple="true"/>		
			</div>
		</div>
		 <div class="control-group">
			<label class="control-label">应到党员：</label>
			<div class="controls">
				<form:textarea path="bmperson" htmlEscape="false" style="width:500px" readonly="true" class="input-xlarge required"/>				
			</div>
		</div>
		 <div class="control-group">
			<label class="control-label">请假党员：</label>
			<div class="controls">
				<form:textarea path="qjperson" htmlEscape="false" style="width:500px"  class="input-xlarge" onclick="selectPersonQj()"/>				
							
			</div>
		</div>
		 <div class="control-group">
			<label class="control-label">实到党员：</label>
			<div class="controls">
				<form:textarea path="sdperson" htmlEscape="false" style="width:500px" readonly="true" class="input-xlarge required"/>				
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">审批意见：</label>
			<div class="controls">
				<form:textarea path="shyj" htmlEscape="false"  rows="4" readonly="true" style="width:800px" class="input-xlarge required"/>	
							
			</div>
		</div>
		<div class="form-actions">
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>